﻿using System;
using System.Collections.Generic;
using Web7.Core.Security;
using Microsoft.Practices.Unity;
using Web7.Container.Models;

namespace Web7.Container.Services
{
    public class AssistRoleService : IAssistRoleService
    {
        [Dependency]
        public IRoleService _RoleService { get; set; }

        [Dependency]
        public IPermissionRecordService _PermissionService { get; set; }

        public void CreatePermissionForRole(string roleName, string permissionName)
        {
            /*throw new NotImplementedException();*/
            //TODO;
        }

        public IDictionary<string, IEnumerable<PermissionRecord>> GetInstalledPermissions()
        {
            /*throw new NotImplementedException();*/
            //TODO;
            return null;
        }

        public IEnumerable<PermissionRecord> GetPermissionsForRole(Guid id)
        {
            return _PermissionService.Fetch(p => p.OwnerId == id);
        }

        public IEnumerable<PermissionRecord> GetPermissionsForRoleByName(string name)
        {
            /*throw new NotImplementedException();*/
            //TODO;
            return null;
        }

        public bool VerifyRoleUnicity(string name)
        {
            var role = _RoleService.Get(r => r.RoleName == name);

            return (role != null);
        }

        public Role CreateRole<T>(T model)
        {
            var m = model as RoleViewModel;
            if (null == m)
            {
                // throw new 
                return null;
            }

            var role = new Role();

            role.Id = SequentialGuid.NewGuid();
            role.RoleName = m.RoleName;
            role.IsSystem = false;
            role.Description = "New role just created";
            role.RoleStatus = 1;

            return role;
        }

    }
}
